package com.yswy.domain.common;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = true)
public class BasePojo<T extends Model<?>> extends Model<T> {
    @TableId(type = IdType.AUTO)
    /** id s **/
    private Long id;
    @ApiModelProperty("创建时间")
    private Date createTime = new Date();
    @ApiModelProperty("创建人")
    private Long createBy;
    @ApiModelProperty("更新时间")
    private Date updateTime;
    @ApiModelProperty("更新人")
    private Long updateBy;
    @ApiModelProperty("是否删除 1:删除 0:未删除")
    private Integer isDel = 0;

    public T createBo(Long optionId) {
        create(optionId);
        return (T) this;
    }

    public void create(Long optionId) {
        this.createTime = new Date();
        if(null == optionId) {
            return;
        }
        this.createBy = optionId;
    }
    public void update(Long optionId) {
        this.updateTime = new Date();
        if(null == optionId) {
            return;
        }
        this.updateBy = optionId;
    }
    public void updateDel(Long optionId) {
        this.isDel = 1;
        update(optionId);
    }
    public void updateDel(Long optionId, Integer isDel) {
        this.isDel = isDel;
        update(optionId);
    }
}
